
*This file to match activeisd_us_station.dta with UserZips.dta

***Inputs:
* $Data/activeisd_us_stations.dta
* $Data/UserZips.dta
* $Data/zip_centroids.dta

***Outputs:
* $Data/activeisd_us_stations_id.dta
* $Data/user_activeisd_us_stations.dta
 
use $Data/activeisd_us_stations.dta, clear
*1. Create ID var for active isd us stations*
	di _N
	gen id = _n //2610
save $Data/activeisd_us_stations_id.dta, replace


	*2. Create ID var for user zips
use $Data/UserZips.dta, clear
	rename zip zip3
	merge 1:1 zip3 using $Data/zip_centroids.dta
	keep if _merge ==3 // not merging some zips from user data.. e.g sacramento
	drop _merge
	expand 2610
	by zip3, sort: gen id =_n
	merge m:1 id using $Data/activeisd_us_stations_id.dta
	drop _merge 
	geodist lat longi LAT LON , generate(isd_dist) miles	

	sort zip3 isd_dist

save $Data/fullzipisdlist_Aug2019.dta, replace
	
	keep if isd_dist <= 30

	duplicates drop

	rename zip3 zip

save $Data/user_activeisd_us_stations_Aug2019.dta, replace
